using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using SpoonCore2.Message;
using SpoonCore2.Message.Filter.Info;
using SpoonCore2.Service;

namespace SpoonCore2.OverlayNetwork.Pastry.Messages
{
	internal class PingMessage : AbstractMessage
	{
		private static readonly Random _rand = new Random();
		private MessageType _type = MessageType.Request;
		private int _id = _rand.Next();
		private readonly DateTime _time = DateTime.Now;

		public enum MessageType : byte
		{
			Request = 0,
			Response = 1
		}

		public MessageType Type
		{
			get { return _type; }
			set { _type = value; }
		}

		public override void GetBytes(BinaryWriter bw)
		{
			bw.Write((byte)_type);
			bw.Write(_id);
		}

		public override void SetBytes(IService service, BinaryReader br)
		{
			_type = (MessageType)br.ReadByte();
			_id = br.ReadInt32();
		}

		public int Id
		{
			get { return _id; }
			set { _id = value; }
		}

		public DateTime Time
		{
			get { return _time; }
		}
	}
}